package yygh.hosp.Service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import yygh.hospital.model.hosp.HospitalSet;
import yygh.hospital.vo.order.SignInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import yygh.common.execption.HospitalException;
import yygh.common.result.ResultCodeEnum;
import yygh.hosp.Service.HospitalSetService;
import yygh.hosp.mapper.HospitalMapper;

@Service
public class HospitalSetServiceImp extends ServiceImpl<HospitalMapper, HospitalSet> implements HospitalSetService {

    @Autowired
    HospitalMapper hospitalMapper;


    @Override
    public HospitalSet getHospitalSetByHoscode(String hoscode) {
        QueryWrapper<HospitalSet> queryWrapper  = new QueryWrapper<>();
        queryWrapper.eq("hoscode",hoscode);
        return hospitalMapper.selectOne(queryWrapper);

    }
    /**
     * 内部接口对应的实现类方法
     * @param hoscode
     * @return
     */
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
            SignInfoVo signInfoVo=new SignInfoVo();
        QueryWrapper<HospitalSet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = hospitalMapper.selectOne(queryWrapper);
        if (hospitalSet==null){
            throw   new HospitalException(ResultCodeEnum.DATA_ERROR);
        }
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return  signInfoVo;
    }
}
